

class Spec():
    '''定义一个期货交易品种的类'''

    name_dict_ine = {'沪原油': 'SC', '20号胶': 'NR'}
    name_dict_shfe = {
        '铜': 'CU',
        '螺纹钢': 'RB',
        '锌': 'ZN',
        '铝': 'AL',
        '黄金': 'AU',
        '天然橡胶': 'RU',
        '铅': 'PB',
        '白银': 'AG',
        '沥青': 'BU',
        '热卷': 'HC',
        '镍': 'NI',
        '锡': 'SN',
        '纸浆': 'SP',
        '不锈钢': 'SS',
        '燃料油': 'FU'
    }
    name_dict_dce = {
        '棕榈油': 'P',
        'PVC': 'V',
        '聚乙烯': 'L',
        '豆一': 'A',
        '豆粕': 'M',
        '豆油': 'Y',
        '玉米': 'C',
        '焦炭': 'J',
        '焦煤': 'JM',
        '铁矿石': 'I',
        '鸡蛋': 'JD',
        '聚丙烯': 'PP',
        '玉米淀粉': 'CS',
        '苯乙烯': 'EB',
        '乙二醇': 'EG',
        '液化石油气': 'PG'
    }
    name_dict_czce = {
        'PTA': 'TA',
        '白糖': 'SR',
        '棉花': 'CF',
        '菜籽油': 'OI',
        '玻璃': 'FG',
        '菜籽粕': 'RM',
        '油菜籽': 'RS',
        '硅铁': 'SF',
        '锰硅': 'SM',
        '甲醇': 'MA',
        '动力煤': 'ZC',
        '棉纱': 'CY',
        '尿素': 'UR',
        '纯碱': 'SA'
    }
    name_dict = {**name_dict_shfe, **name_dict_dce, **name_dict_czce, **name_dict_ine}

    def __init__(self, name):
        self.name = name
        self.symbol = self.name_dict[name]

    def check_exchange(self):
        sy = self.symbol
        if sy in list(Spec.name_dict_ine.values()):
            return 'INE'
        elif sy in list(Spec.name_dict_czce.values()):
            return 'ZCE'
        elif sy in list(Spec.name_dict_dce.values()):
            return 'DCE'
        elif sy in list(Spec.name_dict_shfe.values()):
            return 'SHF'
        else:
            return False

    def get_code(self, contract='L'):
        m_code = self.symbol + contract
        return m_code
